﻿using System;
using System.IO;

namespace FileCom
{
    class FileCom
    {

        public void CombineFile(String[] infileName, String outfileName)
        {
            int b;
            int n = infileName.Length;
            FileStream[] fileIn = new FileStream[n];
            using (FileStream fileOut = new FileStream(outfileName, FileMode.Create))
            {
                for (int i = 0; i < n; i++)
                {
                    try
                    {
                        fileIn[i] = new FileStream(infileName[i], FileMode.Open);
                        while ((b = fileIn[i].ReadByte()) != -1)
                            fileOut.WriteByte((byte)b);
                    }
                    catch (System.Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        fileIn[i].Close();
                    }

                }
            }
        }
    }


    class TestCombine
    {
        public static void Main(String[] args)
        {

            FileCom c = new FileCom();
            String[] file = new String[2];
            file[0] = "Data/aa.txt";
            file[1] = "Data/bb.txt";
            c.CombineFile(file, "Data/cc.txt");
        }
    }
}
